<script setup lang="ts">
import {deleteCategoryUrl} from "@/api/blog/category.ts";

import TagsDialog from "@/views/blog/article/tags/TagsDialog.vue";
import {getTagsListUrl} from "@/api/blog/tags.ts";


const TagsDialogRef = ref(null)
const tableData = ref([])
const total = ref(0)
const formData = ref({
  pageNum: 1,
  pageSize: 10,
  btName: ''
})
const {proxy}: any = getCurrentInstance()

function handleGetList() {
  getTagsListUrl(formData.value).then((res: any) => {
    tableData.value = res.rows
    total.value = res.total
  })
}
const handleCurrentChange = (val) => {
  formData.value.pageNum = val
  handleGetList()
}

const handleDelete = (row) => {
  proxy.$modal.confirm('确定删除该分类吗？').then(() => {
    deleteCategoryUrl({
      btId: row.btId
    }).then((res: any) => {
      proxy.$modal.msgSuccess(res.msg)
      handleGetList()
    })
  })
}
const handleEdit = (row) => {
  TagsDialogRef.value.openDialog(row)
}
const handleAdd = () => {
  TagsDialogRef.value.openDialog()
}


onMounted(() => {
  handleGetList()
})
</script>

<template>
  <div>
    <el-form inline :model="formData" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="formData.btName" placeholder="请输入标签名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleGetList">查询</el-button>
        <el-button type="success" @click="handleAdd">新增</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="btId" label="标签ID"  align="center"></el-table-column>
      <el-table-column prop="btName" label="标签名称" align="center"></el-table-column>
      <el-table-column prop="icon" label="icon" align="center"></el-table-column>
      <el-table-column prop="createTime" label="创建时间" align="center"></el-table-column>
      <el-table-column label="操作" width="180" align="center">
        <template #default="scope">
          <el-button type="text" style="color: #409EFF" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button type="text" style="color: #F56C6C" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        background
        v-if="total > 0"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        v-model:page-size="formData.pageSize"
        v-model:current-page="formData.pageNum"
        :page-sizes="[10, 20, 30, 40, 50]"
        @current-change="handleCurrentChange"
        style="margin-top: 30px; float: right; text-align: center"
    />

    <TagsDialog ref="TagsDialogRef" @getList="handleGetList"/>
  </div>

</template>

<style scoped lang="scss">

</style>
